<layout name="page" />
<block name="content">
	{:widget('page_header/search',array('name'=>'规则分配','search'=>'S'))}
	<div class="operate-panel">
		<div class="split"></div>
		<a id="btn_save" class="btn">保存</a>
	</div>
	<!-- 列表显示区域  -->
	<div class="sub-frame">
		<form id="form_data" name="form_data" method="post" >
			<div class="sub-sidebar big">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th class="checkbox col-2">
							<input type="checkbox" class="toggle-select-all" data="emp_id[]" />
							</th>
							<th>
							<nobr>
								员工编号
							</nobr></th>
							<th>
							<nobr>
								姓名
							</nobr></th>
							<th>
							<nobr>
								部门
							</nobr></th>
							<th class="hidden">
							<nobr>
								职级
							</nobr></th>
							<th>
							<nobr>
								职位
							</nobr></th>
							<th>
							<nobr>
								状态
							</nobr></th>
						</tr>
					</thead>
					<tbody class="tbody">
						<volist name="user_list" id="data">
							<tr class="tlist" id="{$data.id}" >
								<td class="checkbox col-2">
								<input  type="checkbox" name="emp_id[]" value="{$data.id}" />
								</td>
								<td>
								<nobr>
									{$data.emp_no}
								</nobr></td>
								<td>
								<nobr>
									{$data.name}
								</nobr></td>
								<td>
								<nobr>
									{$data.dept_name}
								</nobr></td>

								<td>
								<nobr>
									{$data.position_name}
								</nobr></td>
								<td>
								<nobr>
									{$data.is_del|status}
								</nobr></td>
							</tr>
						</foreach>
					</tbody>
				</table>
			</div>
			<div class="sub-content small">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="pid" id="pid" value="">
				<input type="hidden" name="ajax" id="ajax" value="0">
				<input type="hidden" name="opmode" id="opmode" value="">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th>&nbsp;</th>
							<th>名称</th>
						</tr>
					</thead>
					<tbody class="sid_list">
						<volist name="role_list" id="data">
							<tr guize_id="{$data.id}" onclick="select_user({$data.id})">
								<td class="col-2 checkbox">
								<input  type="checkbox" id="role_{$data.id}" name="role_list[]" value="{$data.id}"/>
								</td>
								<td>{$data.name}</td>
							</tr>
						</foreach>
					</tbody>
				</table>
			</div>
		</form>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use('global', function() {
			$(".sub-sidebar tbody tr").click(function() {
				send_ajax("{:url('get_role_list')}", "id=" + $(this).attr("id"), function(data) {
					show_data(data);
				});
			});
			$("#btn_save").on('click',function(){
				if ($("input:checked[name='emp_id[]']").length < 1) {
					layer.msg("请选择用户");
					return false;
				};
				if ($("input:checked[name='role_list[]']").length < 1) {
					layer.msg("请选择权限");
					return false;
				};
				send_form("form_data", "{:url('set_role')}");
			});
		});
		

		function show_data(result) {
			$(".sid_list>tr").find("input").prop("checked", false);
			$(".sid_list>tr").each(function() {
				guize_id = $(this).attr('guize_id');
				for (var v in result.sid) {
					if (result.sid[v] == guize_id) {
						$(this).find("input").prop("checked", true);
					}
				}
			});
		}

	</script>

</block>